<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 	
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<%@	page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css"/>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/yaodian100.common.js"></script>
<style type="text/css" media="screen">
 <!--      
  select.selCont { margin: 10px; width: 700px; }
 -->
</style>
<script language="javascript">
	$().ready( function() {
		$('#displayAddProduct').hide();
		$('#showNext').hide();
		//商品编号栏位只能输入数值
		$("#pickProductId").numeric();
		$("#pickProductId").blur(function(){
			$(this).val(prodPadLeft($(this).val()));
		});
		//查询商品资料
		$("#findPickProduct").click(function(){
			$.post("${midContextPath}/pickProduct2/findPickProductName.do",{productIdParam:"${product.productId}",isScm:"${product.isScm}",paramProductId:$('#paramProductId').val()},pickProductCallback,"json");
		});

		$("#next").click(function(){
			location.href="${midContextPath}/pickProduct2/shelfSearch.do?productIdParam=${product.productId}";
		});	
		if(${fn:length(addOnProducts)}>0){
			$('#showNext').show();
		}

		$("#addPickProductForm").submit(function(){
			if ( 0 == $(":checkbox[name='addPrds']:checked").size() ){
				alert("请勾择要加入的商品");
				return false;
		  	}
			return true;
		});

		$("#submitdel").click(function(){
			 if ( 0 == $(":checkbox[name='delPrds']:checked").size() ){
					alert("请勾择要删除的商品");
					return false;
			 }else{
		  		$("#pickProductForm").submit();
		  	}
		});	
	});
	//查询挑选的商品资讯
	function pickProductCallback(newAddProducts){
		//查询商品
		if(newAddProducts.length>0){
			//移除舊資料
			$("table#divAddProduct tr").each(function(index){
				if ( index > 0 ){
					$(this).remove();
				}
			});
			for(ii=0; ii<newAddProducts.length;ii++){
				if(newAddProducts[ii].split(',')[4]=='true'){
					$("table#divAddProduct tr:last").after('<tr><td><input id="addPrds_' + ii + '" name="addPrds" type="checkbox" value="'+newAddProducts[ii].split(',')[0]+'" id=""/>'+ newAddProducts[ii].split(',')[0]+'</td>' +
					'<td>' + newAddProducts[ii].split(',')[1] + '</td>' +
					'<td>' + newAddProducts[ii].split(',')[2] + '</td>' +
					'<td>' + newAddProducts[ii].split(',')[3] + '</td>' +
					'<td>OK</td></tr>');
				}else{
					$("table#divAddProduct tr:last").after('<tr><td><input id="addPrds_' + ii + '" name="addPrds" type="checkbox" value="'+newAddProducts[ii].split(',')[0]+'" id="" disabled/>'+ newAddProducts[ii].split(',')[0]+'</td>'+
					'<td>' + newAddProducts[ii].split(',')[1] + '</td>' +
					'<td>' + newAddProducts[ii].split(',')[2] + '</td>' +
					'<td>' + newAddProducts[ii].split(',')[3] + '</td>' +
					'<td>' + newAddProducts[ii].split(',')[5] + '</td></tr>');
				}
			}
			$("table#divAddProduct tr:last").after('<tr><td colspan="5"><input type="submit" id="submitadd" value="加入"/></td></tr>');
			$('#showNext').show();
		}else{
			$("table#divAddProduct tr:last").after('<tr><td colspan="5">查无资料</td></tr>');
		}
		$('#displayAddProduct').show();
	}	
</script>	
<h1>N选M商品管理-挑选N选M商品<br/></h1>
<c-rt:if test="${not empty product.productId}">
	<jsp:include page="commonMenu2.jsp"/>
</c-rt:if>
	<div class="f-link">
		<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/search.do">返回列表页</a>
	</div>
<span class="txt-red"><s:actionerror /></span>
<span class="txt-red"><s:actionmessage /></span>
<span class="txt-red"><s:fielderror /></span>
<br/>
 <div><span class="txt-red">*</span> 表示该项必填</div>


	<table class="tb-data" width="100%">
		<tr>
			<th>* 任选商品编号</th>
			<td>
			<div class="batchtips">
		    ﻿      <h3>使用说明</h3>
		      <div>
		      1. 开放多笔商品编号查询，请以逗号区隔<br>
			  2. 查询商品列表时，若不符合n选m规则，不允许设定<br>
		      3. 若要加入的商品已存在，不允许选取<br>
			  </div>
		    </div>
		    
		    
  		  <textarea name="paramProductId" id="paramProductId" title="商品编号" cols="60" rows="5"/></textarea>
				
				<input type="button" id="findPickProduct" value="查询商品" />
				<BR/><BR/>
				主商品采购模式：  ${isScmMenu.options[product.isScm].name}，供应商：${supplierCompanyName}，限定立即购买商品：${product.nmMustOrderBuy eq 'Y' ? '是' : '否'}
				
			</td>
		</tr>
		
		<table class="tb-data" width="100%">
			<tr>
				<th>新  增  區  域</th>
				<td>
				<div id="displayAddProduct">
				<s:form action="savePickProduct.do" id="addPickProductForm" method="post">
				 	<table class="tb-data" width="100%" id="divAddProduct">
				 		<thead>
					 		<tr>
					 			<th>商品编号</th>
								<th>商品名称</th>
								<th>采购模式</th>
								<th>供应商</th>
								<th>结果</th>
					 		</tr>
					 	</thead>
					 	<tbody>
					 	</tbody>
				 	</table>
				 </s:form>
				 </div>
				</td>
			</tr>
			<tr>
				<th>维  护  區  域</th>
				<td>
					<table class="tb-data" width="100%">
						<tr>
							<th>商品编号</th>
							<th>商品名称</th>
							<th>采购模式</th>
							<th>供应商</th>
							<th>建立者</th>
							<th>建立日期</th>
							<th>修改者</th>
							<th>修改日期</th>
						</tr>
						<s:form action="savePickProduct.do" id="pickProductForm" method="post">
							<c-rt:forEach items="${addOnProducts}" var="addOnProduct">
								<tr>
									<td><input  id="submit_del" name="delPrds" type="checkbox" value="${addOnProduct.addOnProductId}" id="cb_${rows_index.count}"/>${addOnProduct.addOnProductId}</td>
									<td>${productNameMap[addOnProduct.addOnProductId]}</td>
									<td>${isScmMenu.options[modifymProductScmMap[addOnProduct.addOnProductId]].name}</td>
									<td>${modifymProductSupplierMap[addOnProduct.addOnProductId]}</td>
									<td>${addOnProduct.createUser}</td>
									<td><fmt-rt:formatDate value="${addOnProduct.createDate}" pattern="yyyy/MM/dd hh:mm:ss"/></td>
									<td>${addOnProduct.modifyUser}</td>
									<td><fmt-rt:formatDate value="${addOnProduct.modifyDate}" pattern="yyyy/MM/dd hh:mm:ss"/></td>
								</tr>
							</c-rt:forEach>
							<tr><td colspan="8"><input type="button" id="submitdel" value="删除"/></td></tr>
							</s:form>
					</table>
					<br/>	
				</td>
			</tr>
		</table>
			<div id="showNext">
			<a href="${midContextPath}/image2/edit.do?productId=${product.productId}">< 返回上一步</a>
				<input type="button" name="submit2" id="next" value="下一步"/>
			</div>
			<div class="f-link">
				<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/search.do">返回列表页</a>
			</div>
	</table>

